package com.xonro.common.histrans.sfeg.biz.seal;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.UUIDGener;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.ctx.BOCreateData;
import com.xonro.common.histrans.base.ctx.FileTransData;
import com.xonro.common.histrans.base.ctx.HistoryTransContext;
import com.xonro.common.histrans.base.model.HistoryTransLogModel;
import com.xonro.common.histrans.base.consts.SfegConst;
import com.xonro.common.histrans.sfeg.biz.common.SfegRecordTransBiz;
import com.xonro.common.histrans.sfeg.ctx.SfecProcessCreateContext;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class BaseSealBiz  extends SfegRecordTransBiz {
    @Override
    protected void transProcess0(SfecProcessCreateContext historyTransContext) {
        String createUser = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getCreateUser();
        String bindId = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getId();
        Timestamp startTime = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getStartTime();
        List<BOCreateData> boCreateDataList = new ArrayList<>();
        RowMap mainData = historyTransContext.getMainData();
        SDK.getLogAPI().consoleInfo("打印获取的建工印章数据========"+mainData);

        //添加日志
        String mainBOId = UUIDGener.getUUID();
        HistoryTransLogModel logModel = new HistoryTransLogModel();
        historyTransContext.setHistoryTransLogModel(logModel);
        logModel.setBindId(bindId);
        logModel.setBpmBOId(mainBOId);
        logModel.setBpmTable("BO_XR_MDM_SEAL");//项目基础信息
        logModel.setOuterTable("yz_info");//基础项目信息表
        logModel.setOuterPK(mainData.getString("id"));
        logModel.setOuterExt1(mainData.getString("mc"));
        logModel.setOuterExt2(mainData.getString("lx"));//印章类型
        BOCreateData mainBOCreateData = new BOCreateData();
        boCreateDataList.add(mainBOCreateData);
        BO mainBO = new BO();
        mainBOCreateData.setBo(mainBO);
        mainBOCreateData.setCreateUser(createUser);
        mainBO.setCreateDate(startTime);
        mainBO.setUpdateDate(startTime);
        mainBO.setId(mainBOId);
        mainBO.set("SEAL_NO",mainData.getString( "id"));//印章名称
        mainBO.set("SEAL_NAME", mainData.getString("mc"));//印章名称
        mainBO.set("SEAL_ADMIN", mainData.getString("uscode"));//印章保管人编号
        mainBO.set("SEAL_TYPE", mainData.getString("lx"));//印章类型
        mainBO.set("SEAL_IMG", mainData.getString("yzurl"));//印章图片
        mainBO.set("SEAL_LEVEL", mainData.getString("jb"));//印章级别
        mainBO.set("PROJECT_NO", mainData.getString("xmbh"));//项目编号

        historyTransContext.getProcessCreateContext().setBoCreateDatas(boCreateDataList);


        //添加附件
        FileTransData fileTransData = new FileTransData();
        fileTransData.setBoId(mainBOId);
        //印章id
        fileTransData.setFkCode(mainData.getString("id"));
        fileTransData.setProcessInstId(bindId);
        historyTransContext.getFileTransDatas().add(fileTransData);
        mainBOCreateData.setBoName("BO_XR_MDM_SEAL");
        fileTransData.setBoName("BO_XR_MDM_SEAL");
        fileTransData.setFieldName("SEAL_IMG");//印张图片

    }



    @Override
    protected String getProcessDefId() {
        return "obj_1bf69b035dec4c22a9c646a5f3ebab6d";
    }

    @Override
    protected RowMap getMainData() {
        return null;
    }

    @Override
    protected String getActivityDefId() {
        return null;
    }

    @Override
    protected String getTitle(HistoryTransContext ctx) {
        RowMap mainData = ctx.getMainData();
        String mc=mainData.getString("mc");
        String id=mainData.getString("id");
        return mc+id;
    }

    @Override
    protected String getEnCode(HistoryTransContext ctx) {
        RowMap mainData = ctx.getMainData();
        return mainData.getString("suCode");
    }

    @Override
    protected String getOuterTable(SfecProcessCreateContext historyTransContext) {
        return "yz_info";
    }


    @Override
    protected String getPk(SfecProcessCreateContext historyTransContext) {
        RowMap mainData = historyTransContext.getMainData();
        return mainData.getString("id");
    }

    @Override
    protected List<RowMap> getMainDatas() {
        //查询实施单位是康益海洋的公司
        return SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMaps("SELECT * FROM yz_info  WHERE orcode = '1040'  ");
    }
}
